//
//  ViewController.m
//  05--Tom
//
//  Created by Rainy Zou on 15/11/25.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) NSDictionary *dictionary;
@end

@implementation ViewController

-(NSDictionary *)dictionary
{
    if(_dictionary == nil){
        _dictionary = [[NSDictionary alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"tom" ofType:@"plist"]];
    }
    return _dictionary;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnClick:(UIButton *)sender {
    
    if(self.imageView.isAnimating) return;
    
    NSString *action = sender.titleLabel.text;
    int count = [self.dictionary[action] intValue];
    NSMutableArray *images = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        NSString *name = [NSString stringWithFormat:@"%@_%02d.jpg",action,i];
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
        [images addObject:[[UIImage alloc] initWithContentsOfFile:path]];
        
    }
    
    self.imageView.animationImages = images;
    self.imageView.animationDuration = images.count *0.1;
    self.imageView.animationRepeatCount = 1;
    
    [self.imageView startAnimating];
    
}
@end
